import 'package:flutter/material.dart';
import '../../../core/platform/platform_detector.dart';

/// 自适应卡片组件，根据平台调整样式
class AdaptiveCard extends StatelessWidget {
  final Widget child;
  final EdgeInsets? margin;
  final EdgeInsets? padding;
  final Color? color;
  final double? elevation;
  final VoidCallback? onTap;
  final bool withShadow;

  const AdaptiveCard({
    super.key,
    required this.child,
    this.margin,
    this.padding,
    this.color,
    this.elevation,
    this.onTap,
    this.withShadow = true,
  });

  @override
  Widget build(BuildContext context) {
    // 根据平台确定默认值
    final defaultMargin = PlatformDetector.isDesktop()
        ? const EdgeInsets.all(16.0)
        : const EdgeInsets.all(12.0);

    final defaultPadding = PlatformDetector.isDesktop()
        ? const EdgeInsets.all(24.0)
        : const EdgeInsets.all(16.0);

    final defaultElevation = PlatformDetector.isDesktop() ? 4.0 : 2.0;

    return Card(
      margin: margin ?? defaultMargin,
      color: color,
      elevation: withShadow ? (elevation ?? defaultElevation) : 0,
      shape: RoundedRectangleBorder(
        borderRadius:
            BorderRadius.circular(PlatformDetector.getCardBorderRadius()),
      ),
      child: InkWell(
        onTap: onTap,
        borderRadius:
            BorderRadius.circular(PlatformDetector.getCardBorderRadius()),
        child: Padding(
          padding: padding ?? defaultPadding,
          child: child,
        ),
      ),
    );
  }
}
